package com.agentai.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.agentai.framework.common.utils.PageResult;
import com.agentai.framework.common.utils.Result;
import com.agentai.system.convert.SysSerialNoConvert;
import com.agentai.system.entity.SysSerialNoEntity;
import com.agentai.system.service.SysSerialNoService;
import com.agentai.system.query.SysSerialNoQuery;
import com.agentai.system.vo.SysSerialNoVO;
import org.springdoc.core.annotations.ParameterObject;
// import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 系统序列号管理表
*
* @since 1.0.0 2024-11-09
*/
@RestController
@RequestMapping("sys/serial/number")
@Tag(name="系统序列号管理表")
@AllArgsConstructor
public class SysSerialNoController {
    private final SysSerialNoService sysSerialNoService;

    @GetMapping("page")
    @Operation(summary = "分页")
//    @PreAuthorize("hasAuthority('system:serial:page')")
    public Result<PageResult<SysSerialNoVO>> page(@ParameterObject @Valid SysSerialNoQuery query){
        PageResult<SysSerialNoVO> page = sysSerialNoService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
//    @PreAuthorize("hasAuthority('system:serial:info')")
    public Result<SysSerialNoVO> get(@PathVariable("id") Long id){
        SysSerialNoEntity entity = sysSerialNoService.getById(id);

        return Result.ok(SysSerialNoConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
//    @PreAuthorize("hasAuthority('system:serial:save')")
    public Result<String> save(@RequestBody SysSerialNoVO vo){
        sysSerialNoService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
//    @PreAuthorize("hasAuthority('system:serial:update')")
    public Result<String> update(@RequestBody @Valid SysSerialNoVO vo){
        sysSerialNoService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
//    @PreAuthorize("hasAuthority('system:serial:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sysSerialNoService.delete(idList);

        return Result.ok();
    }
}
